Page({
  data:{
    zhanghao:'',
    mima:''
  },
  getZhangHao(e){
    //console.log('账号',e.detail.value)
    this.setData({
      zhanghao:e.detail.value
    })
  },
  getMiMa(e){
    //console.log('密码',e.detail.value)
    this.setData({
      mima:e.detail.value
    })
  },
  login(e){
    let zhanghao=this.data.zhanghao
    let mima=this.data.mima
    console.log("账号",zhanghao,"密码",mima)
    if(zhanghao.length<6 || zhanghao.length>11){
      wx.showToast({
        icon:'none',
        title: '账号输入错误,请输入正确账号',
      })
      return
     }
     if(mima.length<6 || mima.length>6){
      wx.showToast({
        icon:'none',
        title: '密码输入错误,请输入正确密码',
      })
      return
     }
     wx.cloud.database().collection('user').where({
       zhanghao
     }).get({
       success(res){
        console.log("获取数据成功",res)
        let user=res.data[0]
        console.log("user",user)
        if(mima==user.mima){
          console.log('登录成功')
          wx.showToast({
            title: '登录成功',
          })
          
          wx.navigateTo({
            url: '../home/home?name= ' + user.name,
          })
        }else{
          console.log('登录失败')
          wx.showToast({
            icon:'none',
            title: '账号或密码错误',
          })
        }
       },
       fail(res){
        console.log("获取数据失败",res)
       }
     })
  }
})